package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordMoney;
import com.letian.record.service.IRecordMoneyService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录金钱Controller
 * 
 * @author bmz
 * @date 2023-01-15
 */
@RestController
@RequestMapping("/record/money")
public class RecordMoneyController extends BaseController
{
    @Autowired
    private IRecordMoneyService recordMoneyService;

    /**
     * 查询记录金钱列表
     */
    @PreAuthorize("@ss.hasPermi('record:money:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordMoney recordMoney)
    {
        startPage();
        List<RecordMoney> list = recordMoneyService.selectRecordMoneyList(recordMoney);
        return getDataTable(list);
    }

    /**
     * 导出记录金钱列表
     */
    @PreAuthorize("@ss.hasPermi('record:money:export')")
    @Log(title = "记录金钱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordMoney recordMoney)
    {
        List<RecordMoney> list = recordMoneyService.selectRecordMoneyList(recordMoney);
        ExcelUtil<RecordMoney> util = new ExcelUtil<RecordMoney>(RecordMoney.class);
        util.exportExcel(response, list, "记录金钱数据");
    }

    /**
     * 获取记录金钱详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:money:query')")
    @GetMapping(value = "/{moneyId}")
    public AjaxResult getInfo(@PathVariable("moneyId") Long moneyId)
    {
        return success(recordMoneyService.selectRecordMoneyByMoneyId(moneyId));
    }

    /**
     * 新增记录金钱
     */
    @PreAuthorize("@ss.hasPermi('record:money:add')")
    @Log(title = "记录金钱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordMoney recordMoney)
    {
        recordMoney.setOwner(getUsername());
        recordMoney.setCreateBy(getUsername());
        return toAjax(recordMoneyService.insertRecordMoney(recordMoney));
    }

    /**
     * 修改记录金钱
     */
    @PreAuthorize("@ss.hasPermi('record:money:edit')")
    @Log(title = "记录金钱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordMoney recordMoney)
    {
        recordMoney.setUpdateBy(getUsername());
        Long count = recordMoney.getUpdateCount() == null ? 1 : recordMoney.getUpdateCount() + 1;
        recordMoney.setUpdateCount(count);
        return toAjax(recordMoneyService.updateRecordMoney(recordMoney));
    }

    /**
     * 删除记录金钱
     */
    @PreAuthorize("@ss.hasPermi('record:money:remove')")
    @Log(title = "记录金钱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moneyIds}")
    public AjaxResult remove(@PathVariable Long[] moneyIds)
    {
        return toAjax(recordMoneyService.deleteRecordMoneyByMoneyIds(moneyIds));
    }
}
